import api, {BaseUrl} from '../utils/http.js';
import axios from "axios";

// 签到
export async function signIn(data) {
    return api.get('/signIn/' + data);
}

// 签退
export async function signOut(data) {
    return api.get('/checkOut/' + data);

}

// 签到列表
export async function signList(data) {
    return api.get('/selectAttendance', data);
}

export async function signExport() {
    const file = await axios.get(BaseUrl + '/attendance/export', {
        responseType: 'blob', // 重要：指定响应类型为 Blob
        headers: {
            'Content-Type': 'application/json;charset=UTF-8',
            'access-token': localStorage.getItem('token')
        }
    });

    // 创建 Blob 对象
    const blob = new Blob([file.data]);

    // 创建链接并触发下载
    const link = document.createElement('a');
    link.href = window.URL.createObjectURL(blob);
    link.download = '考勤记录.xlsx'; // 设置下载的文件名
    link.click();

    // 释放 URL 对象
    window.URL.revokeObjectURL(link.href);

}

